You're Invited: Meet the Socket team at BSidesSF and RSAC - April 27 - May 1.RSVP
Socket
Sign inDemoInstall
Socket

json-schema-to-ts

Package Overview
Dependencies
Maintainers
1
Versions
81
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-schema-to-ts

Infer typescript types from your JSON schemas!

3.1.1
latest
Source
npm
Version published
Weekly downloads
1.6M
-9.29%
Maintainers
1
Weekly downloads
 
Created

What is json-schema-to-ts?

The json-schema-to-ts npm package is a utility that converts JSON Schema definitions into TypeScript types. This allows developers to ensure type safety and consistency between their JSON data and TypeScript code.

What are json-schema-to-ts's main functionalities?

Convert JSON Schema to TypeScript Types

This feature allows you to convert a JSON Schema into a TypeScript type. The `FromSchema` utility type takes a JSON Schema object and infers the corresponding TypeScript type.

import { FromSchema } from 'json-schema-to-ts';

const userSchema = {
  type: 'object',
  properties: {
    id: { type: 'string' },
    name: { type: 'string' },
    age: { type: 'number' }
  },
  required: ['id', 'name']
} as const;

type User = FromSchema<typeof userSchema>;

const user: User = {
  id: '123',
  name: 'John Doe',
  age: 30
};

Type Validation

This feature ensures that the TypeScript types derived from JSON Schema are validated at compile time, reducing runtime errors and improving code reliability.

import { FromSchema } from 'json-schema-to-ts';

const productSchema = {
  type: 'object',
  properties: {
    productId: { type: 'string' },
    price: { type: 'number' }
  },
  required: ['productId', 'price']
} as const;

type Product = FromSchema<typeof productSchema>;

const product: Product = {
  productId: 'abc123',
  price: 19.99
};

Other packages similar to json-schema-to-ts

Keywords

json

FAQs

Package last updated on 29 Aug 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts